from toee import *
from utilities import *


def san_dialog( attachee, triggerer ):
	if (attachee.leader_get() != OBJ_HANDLE_NULL):
		triggerer.begin_dialog( attachee, 210 )
	elif ( game.quests[31].state == qs_completed ):
		triggerer.begin_dialog( attachee, 250 )
	else:
		triggerer.begin_dialog( attachee, 1 )
	return SKIP_DEFAULT

def san_disband( attachee, triggerer ):
	for obj in triggerer.group_list():
		if (obj.name == 8022):
			triggerer.follower_remove(obj)
	for pc in game.party:
		attachee.ai_shitlist_remove( pc )
		attachee.reaction_set( pc, 50 )
	attachee.runoff(attachee.location-3)
	return RUN_DEFAULT

def san_first_heartbeat( attachee, triggerer ):
	if (game.global_flags[368] == 1) or (game.global_flags[313] == 1):
		if ( attachee.reaction_get( game.party[0] ) >= 0 ):
			attachee.reaction_set( game.party[0], -20 )
	return RUN_DEFAULT

def san_enter_combat( attachee, triggerer ):
	attachee.float_line(12057,triggerer)
	return RUN_DEFAULT

def san_dying( attachee, triggerer ):
	attachee.float_line(12014,triggerer)
	if (attachee.leader_get() != OBJ_HANDLE_NULL):
		game.global_vars[29] = game.global_vars[29] + 1
	return RUN_DEFAULT

def san_new_map( attachee, triggerer ):
	leader = attachee.leader_get()
	if (leader != OBJ_HANDLE_NULL):
		if ((attachee.map == 5062) or (attachee.map == 5066) or (attachee.map == 5067)):
			game.global_flags[204] = 1
		if ((attachee.map == 5051) and (game.global_flags[204] == 1)):
			game.global_flags[204] = 0
			game.timevent_add( leave_group, ( attachee, leader ), 10000 )
	return RUN_DEFAULT

def leave_group( attachee, triggerer ):
	leader = attachee.leader_get()
	if (attachee.map == 5051) and (leader != OBJ_HANDLE_NULL):
		triggerer.begin_dialog( attachee, 400 )
	return RUN_DEFAULT
		

def buttin( attachee, triggerer, line):
	npc = find_npc_near(attachee,8014)
	if (npc != OBJ_HANDLE_NULL):
		triggerer.begin_dialog(npc,line)
		npc.turn_towards(attachee)
		attachee.turn_towards(npc)
	else:
		triggerer.begin_dialog(attachee,160)
	return SKIP_DEFAULT

